//
//  XHMainViewController.swift
//  gu-新浪微博
//
//  Created by xiaohui on 16/6/25.
//  Copyright © 2016年 gusheghui. All rights reserved.
//

import UIKit

class XHMainViewController: UITabBarController {

    override func viewDidLoad() {
        let tabBar = XHTabBar()
        
        //设置代理
        tabBar.xhDelegate = self
        
        setValue(tabBar, forKey: "tabBar")
        
        super.viewDidLoad()
        
        addChildViewController(XHHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(XHMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(XHDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(XHProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    func addChildViewController(childController: UIViewController,title:String,imageName:String){
        
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named:"\(imageName)_selected")
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }

}

extension XHMainViewController:XHTabBarDelegate{
    func composeButtonClick() {

        let nav = UINavigationController(rootViewController: XHComposeViewController())
        
        presentViewController(nav, animated: true) { () -> Void in
            
        }
        
        
    }
}

